package com.ztc.ZtcRouteSite.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.aqgj.util.BaseDaoImpl;
import com.ztc.ZtcRouteSite.bean.ZtcRouteSite;
/**
 * <p>
 *
 * </p>
 *
 * @ClassName ZtcRouteSiteDao
 * @JDK 1.5
 * @author
 * @date
 */
@Repository("ZtcRouteSiteDao")
public class ZtcRouteSiteDao extends BaseDaoImpl<ZtcRouteSite> {
    public String save(ZtcRouteSite ztcRouteSite) {
        this.getHibernateTemplate().save(ztcRouteSite);
        return ztcRouteSite.getId();
    }
    public List<ZtcRouteSite> getAllZtcRouteSites() {
        return this.getAll();
    }
    public String delete(String id,String ztcRouteId) {
    	String sql = "delete from ztc_route_site where 1=1";
		if (id != null) {
			sql += " and id='" + id + "'";
		}
		if (ztcRouteId != null) {
			sql += " and fk_ztc_route_id='" + ztcRouteId + "'";
		}
		if (this.currentSession().createNativeQuery(sql).executeUpdate() >= 0) {
			return "1";
		}
		return "0";
    }
    public List<ZtcRouteSite> searchInfoEquals(ZtcRouteSite ztcRouteSite) {
		String sql = "select * from ztc_route_site where 1=1";
		if (ztcRouteSite.getName() != null) {
			sql += " and name='" + ztcRouteSite.getName() + "'";
		}
		if (ztcRouteSite.getType() != null) {
			sql += " and type='" + ztcRouteSite.getType() + "'";
		}
		if (ztcRouteSite.getAreaCity() != null) {
			sql += " and area_city='" + ztcRouteSite.getAreaCity() + "'";
		}
		if (ztcRouteSite.getAreaCode() != null) {
			sql += " and area_code='" + ztcRouteSite.getAreaCode() + "'";
		}
		if (ztcRouteSite.getLat() != null) {
			sql += " and lat='" + ztcRouteSite.getLat()+ "'";
		}
		if (ztcRouteSite.getFkZtcRouteId() != null) {
			sql += " and fk_ztc_route_id='" + ztcRouteSite.getFkZtcRouteId() + "'";
		}
		if (ztcRouteSite.getId() != null) {
			sql += " and id='" + ztcRouteSite.getId() + "'";
		}
		List<ZtcRouteSite> list = this.currentSession().createNativeQuery(sql,ZtcRouteSite.class).getResultList();
		return list;
	}
	

	public List<ZtcRouteSite> searchInfoLikes(String name, String areaCity) {
		String sql = "select * from ztc_route_site where 1=1";
		if (name != null) {
			sql += " and name like '%" + name + "%'";
		}
		if (areaCity != null) {
			sql += " and area_city like '%" + areaCity + "%'";
		}
		List<ZtcRouteSite> list = this.currentSession().createNativeQuery(sql,ZtcRouteSite.class).getResultList();
		return list;
	}
}